﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Assignment_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public Boolean validateData()
        {
            if (txtStuName.Text.Trim() == "")
            {
                lblCheckSubName.Text = "Please enter Subject Name";
                lblCheckSubName.Visible = true;
                txtStuName.Focus();
                return false;
            }
            lblCheckSubName.Visible = false;

            if (txtProName.Text.Trim() == "")
            {
                lblCheckProName.Text = "Please enter Project Name";
                lblCheckProName.Visible = true;
                txtProName.Focus();
                return false;
            }
            lblCheckProName.Visible = false;

            if (txtEmail.Text.Trim() == "")
            {
                lblCheckEmail.Text = "Please enter Email";
                lblCheckEmail.Visible = true;
                txtEmail.Focus();
                return false;
            }
            lblCheckEmail.Visible = false;
                        
            return true;
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!validateData())
            {
                return;
            }

            if (MessageBox.Show("Bạn chắc chắn muốn Submit dữ liệu", "Submit", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                ResetForm();
            }
            else
            {
                txtStuName.Focus();
                txtStuName.SelectAll();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắc chắn muốn thoát?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                Application.Exit();
            }

        }

        private void ResetForm()
        {
            txtStuName.Text = "";
            txtProName.Text = "";
            rdbYes.Checked = true;
            rdbNo.Checked = false;
            dtpTime.ResetText();
            txtEmail.Text = "";
        }

        private void rdbYes_CheckedChanged(object sender, EventArgs e)
        {
            DateTime today = DateTime.Now;

            if (rdbNo.Checked)
            {
                dtpTime.Value = new DateTime(today.Year, today.Month, today.Day + 1);
                dtpTime.Enabled = false;
            }
            else
            {
                dtpTime.Value = new DateTime(today.Year, today.Month, today.Day);
                dtpTime.Enabled = true;
            }

        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            prdReview.PrintPreviewControl.Zoom = 1;
            prdReview.ShowDialog();
        }

        private void pdDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //chuan bi du lieu nhap tren form member de xuat ra giay in
            string dataInput = "Student Name: " + txtStuName.Text;
            dataInput += "\nProject Name: " + txtProName.Text;
            dataInput += "\nSubmitted: " + (rdbYes.Checked ? "Yes" : "No");
            dataInput += "\nDate of Submitted: " + dtpTime.Text;
            dataInput += "\nEmail  ID: " + txtEmail.Text;

            //in ra may in bang doi tuong Graphic, va phuong thuc drawString();
            Graphics g = e.Graphics;
            g.DrawString(dataInput, txtStuName.Font, Brushes.Red, 20, 50);


        }

        private void btnSetup_Click(object sender, EventArgs e)
        {
            psdSetup.ShowDialog();
            psdSetup.PageSettings.Landscape = true;
        }
    }
}
